package com.yiwei.ydd.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.activity.CommissionDetailActivity;
import com.yiwei.ydd.api.model.CommissionListModel;
import com.yiwei.ydd.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyCommissionDetailAdapter extends ItemAdapter<CommissionListModel.DatasBean, MyCommissionDetailAdapter.DefaultHolder> {


    private final int x24;

    private Context context;

    public MyCommissionDetailAdapter(Context context) {
        super(context);
        this.context = context;
        x24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_commission_detail, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        CommissionListModel.DatasBean item = getItem(position);
        holder.txtPhone.setText(item.mobile);
        //状态（0：未领取，1：已领取）
        if (item.status.equals("0")) {
            holder.txtStatus.setText("待收");
            holder.txtStatus.setTextColor(0xffFB5E01);
        } else if (item.status.equals("1")) {
            holder.txtStatus.setText("已收");
            holder.txtStatus.setTextColor(0xff999999);
        }
        Spanned recharge = Spans.with(context).font("充值资金  ", x24, 0xff999999).
                font(item.money + "元", x24, 0xff333333).
                build();
        holder.txtLeft.setText(recharge);

        Spanned fee = Spans.with(context).font("应收佣金  ", x24, 0xff999999).
                font(item.fee + "元", x24, 0xff333333).
                build();
        holder.txtRight.setText(fee);

        if (item.relation.equals("1")) {
            holder.imgRelation.setImageResource(R.mipmap.img_sign_zhi);
        } else if (item.relation.equals("2")) {
            holder.imgRelation.setImageResource(R.mipmap.img_sign_jian);
        }
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CommissionDetailActivity.class);
                intent.putExtra("id", item.id);
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_phone)
        TextView txtPhone;
        @BindView(R.id.img_relation)
        ImageView imgRelation;
        @BindView(R.id.txt_status)
        TextView txtStatus;
        @BindView(R.id.txt_left)
        TextView txtLeft;
        @BindView(R.id.txt_right)
        TextView txtRight;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String id);
    }
}
